//
//  CYNReactNativeViewController.m
//  App
//
//  Created by blank on 2019-01-23.
//    Copyright © 2019 NowStudio Co.,Ltd. All rights reserved.
//

#import "CYNReactNativeViewController.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Masonry/Masonry.h>

@interface CYNReactNativeViewController ()

@property(nonatomic, retain) RCTRootView *rootView;

@end

@implementation CYNReactNativeViewController

- (void)didInitialize {
    [super didInitialize];
    // init 时做的事情请写在这里
}

- (void)initSubviews {
    [super initSubviews];
    // 对 subviews 的初始化写在这里
    [self.view addSubview:self.rootView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 对 self.view 的操作写在这里
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    [self.rootView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
}

- (void)setupNavigationItems {
    [super setupNavigationItems];
    self.title = @"<##>";
}

- (RCTRootView *)rootView {
    if (!_rootView) {
        NSURL *jsCodeLocation;

#ifdef DEBUG
        jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
        jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

        _rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                moduleName:@"Runner"
                                         initialProperties:nil
                                             launchOptions:nil];
        _rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
    }
    return _rootView;
}


@end
